import { TitleInfo } from "./info/TitleInfo";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { TTitleAreaType } from "../../../Message/Db/Tables/TTitleAreaType";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { ETitleCategory } from "../../../Message/Game/ETitleCategory";
import { Cache } from "../cache/Cache";
import { HTMLUtil } from "../../../com/gengine/utils/HTMLUtil";
type int = number;
//class TitleConfig
    
    export  class TitleConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._arenTypeArray = [];
            if (TitleConfig._instance != null) 
            {
                throw new Error(" ResConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TitleInfo();
                loc1.attribute = StringHelper.getString(loc2.attribute);
                loc1.campExclude = StringHelper.getString(loc2.campExclude);
                loc1.careerLimit = loc2.careerLimit;
                loc1.category = loc2.category;
                loc1.code = loc2.code;
                loc1.condition = StringHelper.getString(loc2.condition);
                loc1.desc = StringHelper.getString(loc2.desc);
                loc1.existTime = loc2.existTime;
                loc1.icon = loc2.icon;
                loc1.iconType = loc2.iconType;
                loc1.level = loc2.level;
                loc1.name = StringHelper.getString(loc2.name);
                loc1.sexLimit = loc2.sexLimit;
                loc1.stacking = loc2.stacking;
                loc1.type = loc2.type;
                loc1.showType = loc2.showType;
                loc1.showArea = loc2.showArea;
                this._map[loc1.code] = loc1;
            }
            return;
        }

        /* internal  */writeArenaType(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TTitleAreaType();
                loc1.id = loc2.id;
                loc1.name = loc2.name;
                loc1.type = loc2.type;
                this._arenTypeArray.push(loc1);
            }
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_title_config.json");
            var loc2=ConfigManager.instance.getJSONByFileName("t_title_area_type.json");
            this.write(loc1);
            this.writeArenaType(loc2);
            return;
        }

        public getInfoByCode(arg1: int): TitleInfo
        {
            return this._map[arg1];
        }

        public getTitleName(arg1: TitleInfo, arg2: Boolean=true): string
        {
            var loc1="";
            if (!arg1) 
            {
                return loc1;
            }
            if (arg1.category != ETitleCategory._ETitleCategoryContribution) 
            {
                if (arg1.category == ETitleCategory._ETitleCategoryMarry) 
                {
                    if (Cache.instance.marry.playerMarry) 
                    {
                        loc1 = loc1 + Cache.instance.marry.playerMarry.mate.name;
                    }
                }
            }
            else if (Cache.instance.guild.myGuildInfo) 
            {
                if (arg2) 
                {
                    loc1 = loc1 + HTMLUtil.replaceHtmlTag(Cache.instance.guild.myGuildInfo.guildName);
                }
                else 
                {
                    loc1 = loc1 + Cache.instance.guild.myGuildInfo.guildName;
                }
            }
            loc1 = loc1 + arg1.name;
            return loc1;
        }

        public getAllAreaType(): Array<any>
        {
            return this._arenTypeArray;
        }

        public static get instance(): TitleConfig
        {
            if (TitleConfig._instance == null) 
            {
                TitleConfig._instance = new TitleConfig();
            }
            return TitleConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_arenTypeArray: Array<any>;

        /* internal */ static /* var */_instance: TitleConfig;
    }
